﻿using System;
using System.Web.UI;
using System.Web.Configuration;
using System.Data;
using System.Web.UI.WebControls;


public partial class manager_temt_Task_Default : System.Web.UI.Page
{
    public string Html_Dept = "";
    public string Html_Dept_Detail = "";
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        ((Label)Master.FindControl("MESS")).Text = (Request.QueryString["mes"]);
        if (!IsPostBack)
        {
            GetDept();
            loadData();
        }
    }

    private void GetDept()
    {
        int i = 0;
        Html_Dept = "";
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            if (i == 0)
            {
                Html_Dept += "<li onclick=\"SetDept('" + dr["id"].ToString() + "','" + dr["mc"].ToString() + "')\" role=\"presentation\" class=\"active\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            else
            {
                Html_Dept += "<li onclick=\"SetDept('" + dr["id"].ToString() + "','" + dr["mc"].ToString() + "')\"  role=\"presentation\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            i = 1;
        }
    }

    private void loadData()
    {
        dept_id.Value = "";
        int i = 0;
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            dept_id.Value = dept_id.Value + "|" + dr["id"].ToString();
            if (i == 0)
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane active\" id=\"dept_" + dr["id"].ToString() + "\">"; }
            else
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane\" id=\"dept_" + dr["id"].ToString() + "\">"; }

            Html_Dept_Detail += "<div class=\"box-body\">";
            Html_Dept_Detail += "<table id=\"table_" + dr["id"].ToString() + "\" class=\"table table-bordered table-striped\">";
            Html_Dept_Detail += "<thead>";
            Html_Dept_Detail += "<tr>";
            Html_Dept_Detail += "<th></th>";
            Html_Dept_Detail += "<th class=\"col-sm-3\">名称</th>";
            Html_Dept_Detail += "<th class=\"col-sm-2\">当前在岗</th>";
            Html_Dept_Detail += "<th class=\"col-sm-3\">操作</th>";
            Html_Dept_Detail += "</tr>";
            Html_Dept_Detail += "</thead>";
            Html_Dept_Detail += "<tbody>";

            string tsql = "select v_dict_dept_position.*from v_dict_dept_position  where dept=" + dr["id"].ToString() + " order by bh";

            DataTable dt1 = db.getList(tsql);
            foreach (DataRow dr1 in dt1.Rows)
            {
                Html_Dept_Detail += "<asp:Repeater runat=\"server\">";
                Html_Dept_Detail += "<ItemTemplate>";
                Html_Dept_Detail += "<tr>";
                Html_Dept_Detail += "<td>" + dr1["id"].ToString() + "</td>";
                switch (dr1["type"].ToString())
                {
                    case "1":
                        Html_Dept_Detail += "<td style=\"color:red\"><b>" + dr1["mc"].ToString() + "</b></td>";

                        break;
                    case "2":
                        Html_Dept_Detail += "<td style=\"color:blue;padding-left:30px;\">" + dr1["mc"].ToString() + "</td>";

                        break;
                    case "3":
                        Html_Dept_Detail += "<td style=\"padding-left:50px;\">" + dr1["mc"].ToString() + "</td>";

                        break;
                }


                Html_Dept_Detail += "<td>" + dr1["userName"].ToString() + "</td>";
                Html_Dept_Detail += "<td><a href=\"TaskTmpSet.aspx?type=" + dr1["type"].ToString() + "&&id=" + dr1["id"].ToString() + "&&title=..." + dr1["mc"].ToString() + "...\">设置任务</a></td>";
                Html_Dept_Detail += "</tr>";
            }
            Html_Dept_Detail += "</tbody>";
            Html_Dept_Detail += "</table>";
            Html_Dept_Detail += "</div>";
            Html_Dept_Detail += "</div>";
            i = 1;
        }
    }
}